<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    	<title>统战成员学习平台</title>
	    <link rel="stylesheet" type="text/css" href="../css/base.css" />
	    <link rel="stylesheet" type="text/css" href="../css/style.css" />
	</head>
	<body>
		<div id='app' style="display:none" v-show="true">
			<header v-if="!isLogin" class="red">
				<div class="ui_border_b">
					<p>课程</p>
				</div>
			</header>
			<div v-if="isLogin" class="top_nav red">
					<div @click="selectType(i, $event)" v-for="(item, i) of types" :class="{'active': i === activeIndex}"><span >{{item.name}}</span></div>
			</div>
			<div v-if="!isLogin" class="no_lesson" :style="{'height': height + 'px','padding-top': '5rem'}">
				<img src="../image/no_lesson_bg.png">
				<p class="tip">您还没有登录，请登录后查看</p>
				<p @click="pageUtil.toLogin()" class="see">登录</p>
			</div>
		</div>
		<script type="text/javascript" src="../script/api.js"></script>
		<script type="text/javascript" src="../script/vue.min.js"></script>
		<script type="text/javascript" src="../script/common.js"></script>
		<script type="text/javascript" src="../script/layer_mobile/layer.js"></script>
		<script type="text/javascript">
		    new Vue({
		     	el: '#app',
		     	data: {
					click : false,
					scrollWidth: 1000,
					activeIndex: -1,
					types: [{frameUrl: 'lesson_frame.html', url: '/client/course/hotCourseList', name: '热点课程'},
						{frameUrl: 'lesson_class_frame.html', url: '/client/course/courseGenreList', name: '课程资源'},
						{frameUrl: 'plan_frame.html', url: '/client/schedule/selectScheduleList', name: '学习计划'}],
					isLogin: false,
					height: 500,
					translateX: 20
		     	},
					computed: {
				    // 计算属性的 getter
				    smallScrollWidth: function () {
				      // `this` 指向 vm 实例
				      return this.scrollWidth/4;
				    }
				  },
		     	mounted: function() {
		        	var $this = this;
		        	apiready = function() {
						// hide this frame
						api.setFrameAttr({
						    name: api.frameName,
						    hidden: true
						});
						api.setStatusBarStyle({color : '#fff'});
						$this.scrollWidth = api.winWidth;
						$this.init();
						$this.addEventListener();
						api.addEventListener({
						    name: 'user_login_logout_event'
						}, function(ret, err){
							$this.init();
						});
                	}
		    	},
		    	methods: {
					init: function() {
			        	var $this = this;
						var userInfo = $api.getStorage(_.USERINFO);
						$this.isLogin = !!userInfo;
						setTimeout(function() {
							// fix header
							var header = document.querySelector(isLogin() ? '.top_nav' : 'header');
							$api.fixStatusBar(header);
							api.setStatusBarStyle({
								style: 'light'
							});
							$this.height = api.frameHeight - $api.offset(header).h-1;

							if(!isLogin()) {
								pageUtil.toLogin();

								api.closeFrameGroup({
									name: 'lessonGroup'
								});
								/**
								页面打开就自动初始化
								*/
								api.setFrameAttr({
										name: api.frameName,
										hidden: false
								});

							} else {
								$this.calcWidth();
								/**
								页面打开就自动初始化
								*/
								api.setFrameAttr({
								    name: api.frameName,
								    hidden: false
								});
								setTimeout(function() {
									$this.openLessonFrameGroup();
								}, 0);
							}
						}, 100);
					},
					addEventListener: function() {
			        	var $this = this;

						api.addEventListener({
							name: 'open_lesson_group_event'
						}, function(ret, err){
							$this.openLessonFrameGroup();
						});

						api.addEventListener({
							name: 'hide_lesson_group_event'
						}, function(ret, err){
							api.setFrameGroupAttr({
								name: 'lessonGroup',
								hidden: true
							});
						});
					},
					calcWidth: function() {

					},
					calcScroll: function(i) {

					},
					selectType: function(i, $event){
						var $this = this;
						if($this.activeIndex === i) return;
						// $this.translateX = $event.target.offsetLeft + ($event.target.offsetWidth - 40) / 2;
						$this.click = true;
						$this.activeIndex = i;

						api.setFrameGroupIndex({
							name : 'lessonGroup',
							scroll: true,
							index : i
						});
						$this.calcScroll(i)
					},
					openLessonFrameGroup: function () {
						var $this = this;
						var header = document.querySelector(isLogin() ? '.top_nav' : 'header');
						$this.activeIndex = 0;

						api.sendEvent({
							name: 'openLessonFrameGroup',
							extra: {
								header: header
							}
						})
					}
		    	}
		    });
		</script>
	</body>
</html>
